<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>分支API测试</title>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>
<body>
    <h1>GitBuild 分支API测试</h1>
    
    <div>
        <h2>测试基础连接</h2>
        <button onclick="testConnection()">测试连接</button>
        <div id="connectionResult"></div>
    </div>

    <div>
        <h2>测试分支获取</h2>
        <input type="text" id="repoUrl" placeholder="输入仓库地址" value="https://github.com/octocat/Hello-World.git" style="width: 400px;">
        <button onclick="testBranches()">获取分支</button>
        <div id="branchResult"></div>
    </div>

    <script>
        async function testConnection() {
            const resultDiv = document.getElementById('connectionResult');
            try {
                resultDiv.innerHTML = '测试中...';
                const response = await axios.get('/api/git/test');
                resultDiv.innerHTML = `<pre style="color: green;">${JSON.stringify(response.data, null, 2)}</pre>`;
            } catch (error) {
                resultDiv.innerHTML = `<pre style="color: red;">错误: ${error.message}\n${JSON.stringify(error.response?.data, null, 2)}</pre>`;
            }
        }

        async function testBranches() {
            const resultDiv = document.getElementById('branchResult');
            const repoUrl = document.getElementById('repoUrl').value;
            
            if (!repoUrl) {
                resultDiv.innerHTML = '<p style="color: red;">请输入仓库地址</p>';
                return;
            }

            try {
                resultDiv.innerHTML = '获取中...';
                
                console.log('开始请求分支:', repoUrl);
                
                const response = await axios.post('/api/git/branches', {
                    repoUrl: repoUrl
                });
                
                console.log('分支响应:', response.data);
                
                resultDiv.innerHTML = `
                    <h3>成功获取 ${response.data.total} 个分支:</h3>
                    <pre style="color: green;">${JSON.stringify(response.data, null, 2)}</pre>
                `;
            } catch (error) {
                console.error('分支获取失败:', error);
                resultDiv.innerHTML = `
                    <h3>获取失败:</h3>
                    <pre style="color: red;">错误: ${error.message}\n${JSON.stringify(error.response?.data, null, 2)}</pre>
                `;
            }
        }

        // 页面加载时自动测试连接
        window.onload = function() {
            testConnection();
        };
    </script>
</body>
</html>
